package com.liang.rabbitmqspringboot.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfiguration {
//: 声明注册fanout模式的交换机

    @Bean
    public FanoutExchange fanoutExchange(){
    return new FanoutExchange("fanout_order_exchange",true,false);
        }

// 2: 声明队列 sms.fanout.queue email.fanout.queue,duanxin.fanout.queue
    @Bean
    public Queue smsQueue(){
        System.out.println("9999999999999999999999999999999999999999999999999999999999999999");
        return new Queue("sms.fanout.queue",true);
    }

    @Bean
    public Queue duanxinQueue(){
        System.out.println("888888888888888888888888888888888888888888888888888888888888");
        return new Queue("duanxin.fanout.queue",true);
    }

    @Bean
    public Queue emailQueue(){
        System.out.println("11111111111111111111111111111111111111111111");
        return new Queue("email.fanout.queue",true);
    }

// 3: 完成绑定关系(队列和交换机完成绑定关系)
    @Bean
    public Binding smsBingding(){
        return BindingBuilder.bind(smsQueue()).to(fanoutExchange());
    }

    @Bean
    public Binding duanxinBingding(){
        return BindingBuilder.bind(duanxinQueue()).to(fanoutExchange());
    }
    @Bean
    public Binding emailBingding(){
        return BindingBuilder.bind(emailQueue()).to(fanoutExchange());
    }


}
